package data_structure;

public class leetcode_0922 {
    public int[] sortArrayByParityII(int[] nums) {
        int len=nums.length;
        int[] even=new int[len/2];
        int[] odd=new int[len/2];
        int num2=0;
        int num1=0;
        for(int i=0;i<len;++i){
            if(nums[i]%2==1){
                odd[num1]=nums[i];
                num1++;
            }
            else{
                even[num2]=nums[i];
                num2++;
            }
        }
        num1--;num2--;
        for(int i=0;i<len;++i){
            if(i%2==1){
                nums[i]=odd[num1];
                num1--;
            }
            else{
                nums[i]=even[num2];
                num2--;
            }
        }
        return nums;
    }
}
